﻿using System;
using System.IO;

namespace Homework12
{
    internal class Program
    {
        /// <summary>
        /// 在指定位置建立目录系统 1\2\3\4\5
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            // 指定根目录路径
            string rootPath = @"D:\CSharpHomework\csharp2024";

            // 定义目录结构
            string[] directories = { "1", "2", "3", "4", "5" };

            try
            {
                // 获取当前路径
                string currentPath = rootPath;

                // 遍历目录数组，创建每个目录
                foreach (var dir in directories)
                {
                    currentPath = Path.Combine(currentPath, dir);
                    if (!Directory.Exists(currentPath))
                    {
                        Directory.CreateDirectory(currentPath);
                        Console.WriteLine($"目录 {currentPath} 已创建。");
                    }
                    else
                    {
                        Console.WriteLine($"目录 {currentPath} 已存在。");
                    }
                }
            }
            catch (Exception ex)
            {
                // 如果发生异常，输出异常信息
                Console.WriteLine("发生错误：" + ex.Message);
            }
            Console.ReadLine();
        }
    }
}
